/**
 * @author Fayçal INAJJARANE
 */
package com.appspot.finajjarane.framework.generic;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.beans.factory.config.BeanDefinition;


@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class EMFactory {

	private static EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional");

	public static EntityManager get(){

		if(!emfInstance.isOpen()){
			emfInstance = Persistence.createEntityManagerFactory("transactions-optional");
		}
		return emfInstance.createEntityManager();

	}

}
